package com.weixing.mall.provider.controller.sys;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.sys.SysMenuDto;
import com.weixing.mall.provider.model.enums.sys.SysFlag;
import com.weixing.mall.provider.model.query.SysMenuQuery;
import com.weixing.mall.provider.model.vo.sys.SysMenuTreeTableVo;
import com.weixing.mall.provider.model.vo.sys.SysMenuTreeVo;
import com.weixing.mall.provider.model.vo.sys.SysMenuVo;
import com.weixing.mall.provider.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统菜单接口
 *
 * @author siashan
 * @since 1.0
 */
@RestController
@RequestMapping("menu")
public class SysMenuController extends BaseController {

    @Autowired
    private IMenuService sysMenuService;

    /**
     * 管理后台菜单树
     * @return 菜单结构树
     */
    @GetMapping("")
    public Result<List<SysMenuTreeTableVo>> menulist(){
        List<SysMenuTreeTableVo> list = sysMenuService.selectSysMenuTreeTableVo(SysFlag.SYS);
        return ResultUtil.success(list);
    }

    /**
     * 代理后台菜单树-treeTable
     * @return 代理后台结构树
     */
    @GetMapping("agentTreeTable")
    public Result<List<SysMenuTreeTableVo>> agentMenulist(){
        List<SysMenuTreeTableVo> list = sysMenuService.selectSysMenuTreeTableVo(SysFlag.AGENT);
        return ResultUtil.success(list);
    }

    /**
     * 展示系统菜单树-tree
     * @return 树
     */
    @GetMapping("tree")
    public Result< List<SysMenuTreeVo>> menuTree(){
        List<SysMenuTreeVo> list = sysMenuService.selectSysMenuTreeVo(SysFlag.SYS);
        return ResultUtil.success(list);
    }

    /**
     * 展示代理商后台菜单树-tree
     * @return 树
     */
    @ApiOperation(value = "")
    @GetMapping("agentTree")
    public Result<List<SysMenuTreeVo>> agentMenuTree(){
        List<SysMenuTreeVo> list = sysMenuService.selectSysMenuTreeVo(SysFlag.AGENT);
        return ResultUtil.success(list);
    }

    @ApiOperation(value = "条件获取系统菜单")
    @GetMapping("getMenu")
    public Result list(SysMenuQuery sysMenuQuery){
        List<SysMenuVo> list = sysMenuService.selectSysMenuVo(sysMenuQuery);
        return ResultUtil.success(list);
    }

    /**
     * 保存系统菜单信息
     *
     * @param sysMenuDto 保存参数
     * @return 保存结果
     */
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated SysMenuDto sysMenuDto){
        sysMenuService.save(sysMenuDto);
        return ResultUtil.success();
    }

    /**
     * 删除菜单
     *
     * @date 2019/7/29 15:43
     * @param id 菜单id
     * @return 删除结果
     */
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return sysMenuService.removeById(id) ? ResultUtil.success() : ResultUtil.error();
    }


}
